package com.jwetherell.my.tree;

import java.util.ArrayList;
import java.util.List;

public class Node<T extends Comparable<T>> {
	
	public Node<T> left;
	public Node<T> right;
	public T data;
	
	public int level = -1;
	public int height = -1;
	
	public Node(T data) {
		this.data = data;
	}

	public Node(Node<T> leftChild, Node<T> rightChild) {
		this.left = leftChild;
		this.right = rightChild;
	}

	public boolean isLeaf() {
		return (this.left == null) && (this.right == null);
	}

	public List<Node<T>> getChildren() {
		if (isLeaf())
			return null;
		
		List<Node<T>> children = new ArrayList<Node<T>>();
		
		if (this.left != null)
			children.add(this.left);
		if (this.right != null)
			children.add(this.right);
		
		return children;
	}

	// setters and getters
	
	public int getHeight() {
		return height;
	}
	
	public void setHeight(int height) {
		this.height = height;
	}
	
	public int getLevel() {
		return level;
	}
	
	public void setLevel(int level) {
		this.level = level;
	}
	
	public T getData() {
		return data;
	}
	
	public void setData(T data) {
		this.data = data;
	}
	
	public Node<T> getLeft() {
		return left;
	}
	
	public void setLeftChild(Node<T> leftChild) {
		this.left = leftChild;
	}
	
	public Node<T> getRight() {
		return right;
	}
	
	public void setRightChild(Node<T> rightChild) {
		this.right = rightChild;
	}

	@Override
	public String toString() {
//		return this.data.toString() + String.format("(H:%d L:%d)", this.height, this.level);
		return this.data.toString();
	}
}